<!-- saved from url=(0026)/test.html -->
<html data-dpr="3" style="font-size: 37.5px;">
<head>
    <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">

    <title>骡窝窝问答,解决旅行问题,基于旅游的问答分享平台 - 骡窝窝</title>
    <meta name="viewport" content="width=device-width,minimum-scale=1.0,maximum-scale=1.0,user-scalable=no,minimal-ui,viewport-fit=cover">
    <meta name="format-detection" content="telephone=no,address=no">
    <meta name="referrer" content="always" />
    <meta name="apple-mobile-web-app-capable" content="no" />
    <meta name="apple-mobile-web-app-status-bar-style" content="no" />

    <link href="/css/mobile+css+head-mobile+css+ui-mobile+css+head_rem^Z1w^1535539097.css" rel="stylesheet" type="text/css">
    <link href="/css/mobile+css+head_rem-mobile+css+ask+new2017+ask-reply-mobile+css+omc+tg_ad1+tg_ad1-mobile+css+ask+new2017+ask-detail^YlRW^1537351708.css" rel="stylesheet" type="text/css">

    <script src="/js/plugins/jquery/jquery.min.js"></script>
    <script src="/js/plugins/form/jquery.form.js"></script>
    <script src="/js/plugins/jrender/jrender.min.js"></script>
    <link rel="stylesheet" href="/js/plugins/dialog2/dialog.css"/>
    <script src="/js/plugins/dialog2/dialog.min.js"></script>
    <script src="/js/common.js"></script>
    <script>
        var user;
        var question;
        var flag = true;

        $(function () {
            user = JSON.parse(sessionStorage.getItem("user"));
            var aid;

            // 获取回答id
            var params = getParams()
            if (params.id) {
                aid = params.id;

                // 获取问题
                $.get("/answers/detail/" + params.id, function (data) {
                    question = data.question;
                    $(".answer-cont").renderValues(data, {
                        getHref: function (item, value) {
                            var href = $(item).data("href");
                            $(item).attr('href', href + value);
                        }
                    });
                    $(".default-pos").renderValues(data,{
                        like: function (item, value) {
                            $(item).attr('onclick', "addLike("+value+",this)");
                            isLike(item, value)
                        }
                    })
                    // 渲染浮动条
                    $("#f_title").attr("href", "/answer.html?id=" + params.id).html("<h2>"+ data.question.title +"</h2>");
                    $(".comm_c").html(data.commentCount);
                    $("#fav_c").html(data.favs);
                    if (data.golden) {
                        $("#answer-section").addClass("a-goldmedal");
                    }
                })
            }

            /*
            // sb方法
            $("#_j_show_comment").click(function () {
                $.get("/answers/comments/" + aid, function (data) {
                    $.each(data, function (index, ele) {
                        $("#comment").after(
                            '<section class="ask-comment" ><h2>评论</h2>'+
                            '<div class="com-lst"><ul><li class="clearfix _j_comment">'+
                            '<div class="img"><img src="'+ ele.user.headImgUrl +'"></div><div class="info"><div class="clearfix">'+
                            '<span>'+ ele.user.nickName +'</span><div class="user-lv lv-s3">Lv5</div><i></i></div>'+
                            '<p>'+ ele.content +'</p></div></li></ul></div></section>'
                        )
                    })
                })
            })*/

            //var flag = true;
            // 评论显示
            $("#_j_show_comment").click(function () {
                if (flag){
                    if (!(parseInt($(".comm_c").html()) == 0)){
                        // 获取评论并渲染
                        $.get("/answers/comments/" + aid, function (data) {
                            // 修改display
                            $(".ask-comment").toggle();
                            $(".com-lst").renderValues({
                                list: data
                            })
                        })
                        flag = false;
                    } else {
                        $(document).dialog({
                            type : 'notice',
                            infoText: '还没有评论',
                            autoClose: 1000,
                            position: 'bottom'  // center: 居中; bottom: 底部
                        });
                    }
                } else {
                    $(".ask-comment").toggle();
                }
            })

            // 发表评论--开启评论浮层
            $("._j_comment_btn").click(function () {
                if(!user){
                    $(document).dialog({
                        type : 'confirm',
                        closeBtnShow: true,
                        content: '登陆后才可以评论, 现在登录?',
                        onClickConfirmBtn: function(){
                            location.href = "/login.html?authorId=666";
                        }
                    });
                }else{
                    $("#_j_comment_dialog").toggle();
                }
            });
            // 关闭评论浮层
            $("._j_close_comment_dialog").click(function () {
                $("#_j_comment_dialog").toggle();
            });
            // 发表评论--提交评论
            $("._j_submit_comment").click(function () {
                var commentContent = $("#_j_comment_content").val();
                $.post("/answers/comments/" + aid, {content:commentContent, questionId: question.id}, function (data) {
                    if (data.success) {
                        location.reload();
                    }
                })
            });
        })

        // 回显顶
        function isLike(item, aid) {
            if (user){
                $.ajax({
                    url: "/users/"+user.id+"/answers/"+aid+"/islike",
                    async: false, // key
                    success: function (data) {
                        if (data){
                            $(item).children("#ding").addClass("on");
                        }
                    }
                })
            }

        }

        // 顶
        function addLike(aid, item) {
            if(!user){
                $(document).dialog({
                    type : 'confirm',
                    closeBtnShow: true,
                    content: '登陆后才可以顶, 现在登录?',
                    onClickConfirmBtn: function(){
                        location.href = "/login.html?authorId=666";
                    }
                });
            }else{
                toggleLike(aid, item)
            }
        }

        // 切换顶图标
        function toggleLike(aid, item) {
            if ($(item).children("#ding").hasClass("on")){
                $.ajax({
                    url: "users/"+user.id+"/answers/"+aid+"/dellike",
                    data: {uid: user.id, aid: aid},
                    type: "DELETE",
                    success: function (data) {
                        if(data.result){
                            $(item).children("#ding").removeClass("on");
                            $(item).children("#b").html(data.result.likes)
                        }
                    }
                })
            } else {
                $.ajax({
                    url: "users/"+user.id+"/answers/"+aid+"/addlike",
                    data: {uid: user.id, aid: aid},
                    type: "PUT",
                    success: function (data) {
                        if(data.result){
                            $(item).children("#ding").addClass("on");
                            $(item).children("#b").html(data.result.likes)
                        }
                    }
                })
            }

        }
    </script>
</head>
    <!--题头-->
    <header class="MfwHead ">
        <div class="LBtn"><a class="btn back"
                             href="javascript:void(window.history.length &gt; 1 ? window.history.back() : document.location.href= '/index.html')"
                             id="_j_top_history_back"></a>
        </div>
        <div class="CBtn"><h1>骡窝窝问答</h1></div>
        <div class="RBtn">
        </div>
    </header>

    <div class="container no-padding">
        <!--浮动问题标题-->
        <section class="ask-tit">
            <a id="f_title">
                <h2></h2>
            </a>
        </section>
        <!--回答正文-->
        <section class="answer-cont" id="answer-section">
            <!--回答用户信息-->
            <a data-href="/mine/userProfiles.html?id=" render-key="user.id" render-fun="getHref">
                <div class="user clearfix">
                    <p><img render-src="user.headImgUrl"></p>
                    <span render-html="user.nickName"></span>
                    <div class="user-lv lv-s3">Lv21</div>
                    <i render-html="createTime"></i>
                </div>
            </a>
            <!--回答-->
            <div class="ans-article" style="height: auto; overflow-y: auto;" render-html="content">
            </div>

            <!--<div class="expand-more">
                <div id="omc_continue_1" style="margin-top:-1rem;">
                    <a data-more="j_see_more" style="margin-bottom:.1rem" class="downarrow-btn" href="javascript:;">
                        <img src="https://images.mafengwo.net/mobile/images/ask/new2017/down-open.png" alt="">
                    </a>
                    <a class="comtext" style="display: none;" data-url="https://m.mafengwo.cn/wenda/detail-10222289-11270930.html" href="javascript:;">App内查看完整回答</a>
                </div>
                <div id="omc_continue_0" class="continue-btn" style="display: none;">
                    <a data-more="j_see_more" style="margin-bottom:.1rem" href="javascript:;"><span class="l-btn">继续阅读</span></a>
                    <a data-url="https://m.mafengwo.cn/wenda/detail-10222289.html" class="r-a" href="javascript:;"><span class="r-btn">查看更多优质回答</span></a>
                </div>
                <div id="omc_continue_2" style="display: none;">
                    <a class="comtext" data-url="https://m.mafengwo.cn/wenda/detail-10222289-11270930.html" href="javascript:;">打开马蜂窝查看剩下1036字 &gt;</a>
                </div>
            </div>-->

            <!--看评论-->
            <div class="clearfix db-int" style="padding-top: 0.53333rem;">
                <a id="_j_show_comment" href="javascript:"><span class="comm_c"></span>条评论</a>
                <p><span id="fav_c"></span>收藏</p>
            </div>
        </section>
        <div class="space" id="comment" style=""></div>
        <!--评论, 需要动态拼接-->
        <section class="ask-comment" style="display: none;">
            <h2>评论</h2>
            <div class="com-lst">
                <ul render-loop="list">
                    <li class="clearfix _j_comment">
                        <div class="img"><img render-src="list.user.headImgUrl"></div>
                        <div class="info">
                            <div class="clearfix">
                                <span render-html="list.user.nickName"></span><div class="user-lv lv-s3">Lv5</div><i></i>
                            </div>
                            <div class="clearfix">
                                <span render-html="list.createTime"></span>
                            </div>
                            <p render-html="list.content"></p>
                        </div>
                    </li>
                </ul>
            </div>
        </section>
    </div>
    <!--点赞, 发表评论-->
    <section class="ft-cont default-pos">
        <a class="laud _j_vote on" render-key="id" render-fun="like"><i id="ding"></i><b id="b" render-html="likes"></b></a>
        <a class="_j_comment_btn" data-num="0"><b >评论</b><span class="comm_c"></span></a>
    </section>
    <!--评论浮层-->
    <section class="reply_box bgef" id="_j_comment_dialog" style="display: none;">
        <div class="reply_title">
            <div class="re-hd">我要评论</div>
            <div class="btn">
                <a class="close _j_close_comment_dialog"><i></i></a>
                <a class="submit _j_submit_comment"><i></i></a>
            </div>
        </div>
        <div class="reply-wrap"><textarea id="_j_comment_content"></textarea></div>
    </section>

</body>
</html>